<?php
class MemberAction extends ContentAction{
	function index(){		
		$dao = M("Member");
		if($_REQUEST['keyword']){
		$map['user_id'] = array("like","%".intval($_REQUEST['keyword'])."%");
		}
		//取得满足条件的记录总数
		$count = $dao->where ( $map )->count (); 
		if ($count > 0) {
			import ( "@.ORG.Page" );
			//创建分页对象
			$listRows = 15;
			if (! empty ( $_REQUEST ['listRows'] )) {
				$listRows = $_REQUEST ['listRows'];
			}
			$page = new Page ( $count, $listRows );
			//分页查询数据
			$voList = $dao->where($map)->order("user_id DESC")->limit($page->firstRow . ',' . $page->listRows)->select ( );
			//分页显示
			$page = $page->show ();
			//模板赋值显示
			$this->assign ( 'list', $voList );
			$this->assign ( 'page', $page );
		}
		$this->cat_id = $_REQUEST['cat_id'];
		$this->listRows = $_REQUEST['listRows'];
		
		$this->display();
	}
	function add(){
		$this->display('edit');
	}
	function edit(){
		$where['user_id'] = $_GET['id'];
		$this->vo = M("Member")->where($where)->find();
		$this->display();
	}
	function update(){
		$data = $_POST;
		$dao = M("Member");
		$where['user_id'] = $data['user_id'];
		$user = $dao->where($where)->find();
		//echo $dao->getLastSql();exit();
		if(empty($user)){
			$this->success("缺少必要参数");
			exit();
		}
		if($data['password_str']){
			$data['password'] = md5(md5(trim($data['password_str'])).$user['salt']);
		}
		$r = $dao->where($where)->save($data);
		if($r){
			$this->success("提交成功",$_POST['forward']);
		}else{
			$this->success("提交失败");
		}		
	}
	function delete(){
		if($_GET['id']){
			$map['user_id'] = $_GET['id'];
			$r = M("Member")->where($map)->delete();
			if($r){
				$this->success("提交成功");
			}else{
				$this->success("提交失败");
			}
		}else{
			$this->success('缺少必要参数');
		}
	}
}